package dao

import (
	"permange/models"
)
//通过gorm对数据库进行增删改添操作
func Selectdepartment() ([]models.Department, error){
	var Department []models.Department
	err := db.Table("department").Order("did ASC").Find(&Department).Error//查询所有数据并按照升序输出
	return Department ,err
}
func Selectdepartment_e(edepartment string) ([]models.Employee,error) {
	var Employee []models.Employee
	err := db.Table("employee").Where("edepartment = ?",edepartment).Find(&Employee).Error//查询所有数据并按照升序输出
	return  Employee, err
}
func Adddepartment(department models.Department) error {
	err := db.Table("department").Create(&department).Error//插入一行从前端发送过来的数据并且向数据库里添加新的元组
	return err
}
func Updatedepartment(department models.Department) error{
	err := db.Table("department").Where("did = ?",department.Did).Updates(&department).Error//根据前端传来的数据选择与其车牌号一致的元组进行更改
	return err
}
func Deletedepartment(id string)  error {
	err := db.Table("department").Where("did = ?",id).Delete(models.Department{}).Error//根据前端输入的id进行删除
	return err
}